package com.codef.sharp.gateway.props;

import cn.hutool.core.collection.CollUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanrf
 * @date 2022/1/26 09:20
 */
@ConfigurationProperties(prefix = "gateway.auth")
public class AuthProperties {
    /**
     * 白名单，网关不检验
     */
    private List<String> whites = new ArrayList<>();

    /**
     * 是否开启网关鉴权
     */
    private boolean enable = false;

    /**
     * 默认的白名单
     */
    private static final String[] DEFAULT_WHITES = {
            "/oauth/**",
            "/actuator/**",
            "/v2/api-docs/**",
            "/v2/api-docs-ext/**",
            "/swagger/api-docs",
            "/swagger-ui.html",
            "/doc.html",
            "/swagger-resources/**",
            "/webjars/**",
            "/druid/**",
            "/error/**",
            "/assets/**",
            "/auth/logout",
            "/auth/code",
            "/captcha/**"
    };

    public AuthProperties() {
        CollUtil.addAll(whites, DEFAULT_WHITES);
    }

    public List<String> getWhites() {
        return whites;
    }

    public void setWhites(List<String> whites) {
        this.whites = whites;
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }
}
